/**************************************************************************
 * @doc EMV
 * @module EMVLib.h |
 * Header file for interfacing SoftPay to BLR EMV library. Contains defines and structures.
 *
 * Product     :   SoftPay 2000 (Global Payment Methodology).
 * <nl>Developer   :
 * <nl>Notes       :
 *
 * @head3 EMV Functions |
 * @index | EMV
 * @end
 *
 * Copyright (c) 1996-2000 by VeriFone Inc. All rights reserved.
 *
 * No part of this software may be used, stored, compiled, reproduced,
 * modified, transcribed, translated, transmitted, or transferred, in any form
 * or by any means whether electronic, mechanical, magnetic, optical,
 * or otherwise, without the express prior written permission of VeriFone, Inc.
 *
 * Revision History
 * ------------------------------------------------------------------------
 $Log: /APACS40/SPK2SIM/Source/Include/EMVLib.h $
 *
 * 3     26/10/00 17:01 Andy_w2
 *
 * 7     7/09/00 16:48 Andy_w2
 *
 * 6     25/08/00 16:22 Andy_w2
 *
 * 5     24/08/00 16:23 Andy_w2
 *
 * 4     23/08/00 15:38 Andy_w2
 *
 * 3     23/08/00 11:29 Andy_w2
 *
 * 2     22/08/00 16:41 Andy_w2
 *
 * 1     21/08/00 16:13 Andy_w2
 * Used to interface SoftPay to BLR EMV library
 * ------------------------------------------------------------------------
 ********************************************************************************/
#ifndef EMVLIB_H
#define EMVLIB_H


// Structure used to keep all necessary EMV configuration data after it has
// been assigned by scheme/issuer/acquirer

#define MAX_DEF_TDOL            32
#define MAX_DEF_DDOL            48
#define MAX_ISS_SCRIPT_RES      25		// Max size of Issuer Script Results (5 scripts processed)


#ifndef __BYTE__
#define __BYTE__
typedef unsigned char     BYTE;
#endif

typedef struct _EMVconfig
{
	// Info needed for Random Online Selection
	unsigned long floor_limit;
	unsigned long threshold;	// Threshold Value for Biased random Selection.
	int random_select_pc;		// Target Percentage for Random Selection.
	int max_biased_pc;			// Maximum Target Percentage.

	byte TACdenial[5];			// Terminal Action Codes
	byte TAConline[5];
	byte TACdefault[5];

	byte DefaultTDOL[MAX_DEF_TDOL+1]; // Includes length BYTE
	byte DefaultDDOL[MAX_DEF_DDOL+1]; // Includes length BYTE

	byte AutoSelect; 	// not 0 => don't ask user to select application,
					  	// just take appl. with highest priority.
	byte EasyEntry;		// Is this an Easy Entry transaction?

	byte IssuerScriptResults[MAX_ISS_SCRIPT_RES + 1];	// This is not config. data, but it has no EMV tag
														// so put it in global structure
} EMV_CONFIG;

#define FLOOR_LIMIT       EMVGlobConfig.floor_limit
#define RS_THRESHOLD      EMVGlobConfig.threshold
#define RS_TARGET_PERCENT EMVGlobConfig.random_select_pc
#define RS_MAX_PERCENT    EMVGlobConfig.max_biased_pc
#define TACDENIAL         EMVGlobConfig.TACdenial
#define TACONLINE         EMVGlobConfig.TAConline
#define TACDEFAULT        EMVGlobConfig.TACdefault
#define DEFAULT_TDOL      EMVGlobConfig.DefaultTDOL
#define DEFAULT_DDOL      EMVGlobConfig.DefaultDDOL
#define EASY_ENTRY        EMVGlobConfig.EasyEntry
#define AUTO_SELECT       EMVGlobConfig.AutoSelect
#define ISS_SCRIPT_RES    EMVGlobConfig.IssuerScriptResults


#define HOST_AUTHORISED         1
#define HOST_DECLINED           2
#define FAILED_TO_CONNECT       3

#define GEN_AAC                 0x00
#define GEN_TC                  0x40
#define GEN_ARQC                0x80

// Merchant Decision
#define FORCE_ONLINE			1
#define FORCE_DECLINE			2

#define CASHBACK_AMT            1
#define SALE_AMT                2

#define MAX_CARD_APPS           10
#define EMV_MAX_SCRIPT_SIZE     255
#define EMV_MAX_ISSUER_AUTH_SIZE    16

#ifndef  TIMED_OUT
#define  TIMED_OUT				-2
#endif

#ifndef  EMV_CANCELLED
#define  EMV_CANCELLED			-3
#endif


void    vdEMVDisplayErrorMsg(EMVResult val);
unsigned short  usEMVInitCard(void);
unsigned short usEMVChooseApplication(TRANSACTION_OBJECT *pobTran, int inAutoSelect, srAIDList *psrTerminalAIDList, srAIDList *psrCandidateList);
   //jrd one source
    #ifdef __arm
    unsigned short usEMVSelAppFromAIDList(int, const srAIDList *, int);
    #endif
    #ifdef _TARG_68000
     unsigned short usEMVSelAppFromAIDList(int inAutoSelect, const srAIDList *psrCandidateList, int inOrigNumApps, int (*inMenuFunc) (char **, int));
    #endif

int		inEMVmenu(char *items[], int num_items);
unsigned short usEMVUseHostData(int HostDecision);
void vdEMVRemoveCard(void);
void  vdEMVAddAmountToPool(char *amtbuff, int type);

void    hex_2_asc(BYTE *, BYTE *, int);
void    ascii_to_bin(BYTE *, BYTE *, int);

void vdGetEMVS71FName (char *pchFName);
void vdGetEMVS72FName (char *pchFName);
int inSetEMVScriptFile(char *pszFileName, unsigned char ucTag, char *pucScript, unsigned short usDataLen);
int inResetEMVScriptFile(void);
//jrd one source
    #ifdef __arm
    int inProcessScripts(char *szFileName, int inScriptType, srTxnResult *psrTvrTsi);
    #endif
    #ifdef _TARG_68000
    unsigned short inProcessScripts(char *szFileName, int inScriptType, srTxnResult *psrTvrTsi);
    #endif

VS_BOOL fScript71(void);
VS_BOOL fScript72(void);

EMVResult usGetSplitSalesAmt(unsigned long *);
EMVResult usGetLastSamePANAmt(unsigned long *);


#endif
